﻿@{
    ViewBag.Title = "GetBillGood";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js?ver=1")" type="text/javascript"></script>
}
<style type="text/css">
    .attrb{
        font-size:12pt;
        color:#5c5c5c;
    }
</style>
<form id="form1" method="post">
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
        <table style="width:100%;">
            <tr>
                <td style="white-space:nowrap;">
                    @Html.Partial("~/Views/Modular/SearchInfo.cshtml")
                </td>
                <td style="width:100%;">
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-ok" onclick="onSelectGoods" plain="true">选择</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>
    <div id="layout1" class="mini-layout" style="width:100%;height:100%;" borderStyle="border:solid 1px #aaa;">

        <div title="商品分类" showProxyText="true" region="west" width="170" expanded="true" showSplitIcon="true">
            <div class="mini-fit">
                <ul id="tree1" class="mini-tree" url=""
                    style="width:100%;height:100%;" expandOnLoad="0"
                    textField="FName" idField="FItemID" parentField="FParentID" showTreeIcon="true" resultAsTree="false">
                </ul>
            </div>
        </div>

        <div title="center" region="center">
            <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%; height:100%; top: 0px; left: 0px;overflow:hidden;border:none;" plain="true">
                <div name="SelectGoods" title="商品列表" style="height:100%;overflow:hidden;">
                    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="10" idField="FItemID"
                         allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true"
                         borderStyle="border:0;" url="../Bill/GetRequireGood" multiSelect="true"
                         allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"
                         sortMode="client" ondrawcell="DrawCell" allowResizeColumn="false"
                         onselect="selectRow" onrowdblclick="adds">
                        <div property="columns">
                            <div type="checkcolumn"></div>
                            <div type="indexcolumn" width="35" headerAlign="center">序号</div>
                            <div field="FPic" name="FPic" width="60" headeralign="center" allowsort="true" style="font-size:12pt !important;">图片</div>
                            <div field="FCode" width="100" allowSort="true" headerAlign="center">条码</div>
                            <div field="FName" width="160" allowSort="true" headerAlign="center">名称</div>
                            <div field="FSpec" width="100" allowSort="true" headerAlign="center">规格</div>
                            <div field="FUnitName" width="50" allowSort="true" headerAlign="center" align="center">单位</div>
                            <div field="FConvert" width="50" allowSort="true" headerAlign="center" align="center">内装数</div>
                            <div field="FPrice" name="FPrice" width="60" numberFormat="#,0.00" headerAlign="center" align="right">单价</div>
                            <div field="FStockQty" name="FStockQty" width="60" numberFormat="#,0.00" headerAlign="center" align="right">库存</div>
                            <div field="FRequireState" name="FRequireState" width="60" headeralign="center" align="center" allowsort="true">售罄/有货</div>
                            <div field="FNumber" width="90" allowSort="true" headerAlign="center">编码</div>
                            <div field="FCorpName" width="80" allowSort="true" headerAlign="center">所属商户</div>                            
                            <div name="action" width="60" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;"></div>
                        </div>
                    </div>
                </div>
                <div name="ShoppingCart" title="已选商品" style="height:100%;">
                    <div>
                        <table>
                            <tr>
                                @*<td><input type="button" value=">" onclick="adds()" style="width:40px;" /></td>
                                <td><input type="button" value=">>" onclick="addAll()" style="width:40px;" /></td>*@
                                <td><input type="button" value="全部取消" @*value="&lt;&lt;"*@ onclick="removeAll()" style="width:100px;" /></td>
                                <td><input type="button" value="取消选中项" @*value="&lt;"*@ onclick="removes()" style="width:100px;" /></td>
                            </tr>
                        </table>
                        <div id="datagrid2" class="mini-datagrid" style="width:100%;height:388px;" idField="FItemID" multiSelect="true"
                             borderStyle="border:0;" url="" allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"
                             onrowdblclick="onOk" sortMode="client" showPager="false" ondrawcell="DrawCell" onselect="selectRow"
                             editNextOnEnterKey="true"  editNextRowCell="true">
                            <div property="columns">
                                <div type="checkcolumn"></div>
                                <div type="indexcolumn" width="35" headerAlign="center">序号</div>
                                <div field="FPic" name="FPic" width="60" headeralign="center" allowsort="true" style="font-size:12pt !important;">图片</div>
                                <div field="FCode" width="100" allowSort="true" headerAlign="center">条码</div>
                                <div field="FName" width="160" allowSort="true" headerAlign="center">名称</div>
                                <div field="FSpec" width="100" allowSort="true" headerAlign="center">规格</div>
                                <div field="FUnitName" width="50" allowSort="true" headerAlign="center">单位</div>
                                <div field="FPrice" name="FPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right">单价</div>
                                <div field="FNumber" width="90" allowSort="true" headerAlign="center">编码</div>
                                <div field="mFQty" name="mFQty" width="70" headerAlign="center" align="right"> 数量
                                    <input property="editor" class="mini-spinner" maxValue="99999999" style="width:100%;" changeOnMousewheel="false" showbutton="false" increment="0" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div title="商品详情" showProxyText="true" region="east" showHeader="false" width="300" showSplitIcon="true">
            <div>
                <table style="height:100%;">
                    <tr>
                        <td style="width:300px;height:300px;">
                            <img id="FMainPic" style="width:300px;height:300px;" />
                        </td>
                    </tr>
                    <tr>
                        <td class="attrb">
                            <div><span>商品名称：</span><span id="FName"></span></div>
                            <div><span>商品条码：</span><span id="FCode"></span></div>
                            <div>
                                <span>商品规格：</span><span id="FSpec"></span>
                            </div>
                            <div>
                                <span>商品单位：</span><span id="FUnit"></span>
                            </div>
                            <div>
                                <span>内装数：</span><span id="FConvert"></span>
                            </div>
                            <div>
                                <span>配送单价：</span><span id="FRmoPrice"></span>
                            </div>
                            <div>
                                <span>商品编码：</span><span id="FNumber"></span>
                            </div>
                            <div>
                                <span>库存数量：</span><span id="FStockQty"></span>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

    <table style="width:100%;">
        <tr>
            <td width ="50px" align="right">提示：</td>
            <td style="width:100%;">
                1、分店自建的商品及总店不允许要货的总店商品不显示在该商品列表。2、售罄的商品为红色字体，不可选择。
            </td>
        </tr>
    </table>

    <script type="text/javascript">
        mini.parse();
        var mBillType = "0";
        var mStockID = 0;
        var FObjectID = 0;
        var uID = parent.window.getSystemAppID();
        var grid1 = mini.get("datagrid1");
        var grid2 = mini.get("datagrid2");

        var h = window.innerHeight || document.body.clientHeight;
        var he = h - 47 - 28;
        $('.mini-layout').css('height', he + 'px');
        $('#datagrid2').css('height', he + 'px');
        $('.mini-tabs-body-top').css('height', he + 'px');

        grid1.on("beforeselect", function (e) {
            if (e.record.FRequireStop == 1) e.cancel = true;
        });

        grid1.on("drawcell", function (e) {
            var record = e.record;
            if (record.FRequireStop == 1) {
                e.cellStyle = "color:red;";
            }
        });

        //通用shown自动调用些方式
        function FormShown() {
            if (mBillType == 1 || mBillType == -1 || mBillType == 10 || mBillType == 11 || mBillType == 12 || mBillType == 20)
                InitGrid("GetBillGoods");
            var tree = mini.get("tree1");
            tree.on("nodeselect", function (e) {
                LoadListData();
            });
        }

        //加载分类树
        function LoadListTree() {
            var tree = mini.get("tree1");
            var mAppID = parent.window.getSystemAppID();
            var json = '[{"mSystemAppID":"' + mAppID + '"}]'
            $.post('../Goods/GetGoodsClass', { mjson: mAppID }, function (data) {
                tree.loadList(mini.decode(data));
                tree.select(0);
            });
        }

        function setkeyPress() {
            if (event.keyCode == 13) {
                LoadListData();
            }
        }

        //加载资料
        function SetData(data) {
            if (data.key != null) {
                mini.getbyName("FSearchKey").setValue(data.key);
            }
            if (data.mBillType != null) {
                mBillType = data.mBillType;
            }
            if (data.mStockID != null) {
                mStockID = data.mStockID;
            }
            if (data.FObjectID != null) {
                FObjectID = data.FObjectID;
            }
            LoadListTree();
        }

        //加载资料
        function search() {
            LoadListData();
        }

        //加载用户列表
        function LoadListData() {
            var tree = mini.get("tree1");
            var mload = tree.getData();
            if (mload.length > 0) {
                var node = tree.getSelectedNode();
                var classid = node.FItemID;
                var json = "[{";
                json = json + "'FClassID':" + "'" + classid + "',";
                json = json + "'FBillType':" + "'" + mBillType + "',";
                json = json + "'FNumber':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
                json = json + "'FStockID':'" + mStockID + "',";
                json = json + "'FObjectID':'" + FObjectID + "',";
                json = json + "'FSystemAppID':'" + parent.window.getSystemAppID() + "'}]";
                var grid = mini.get("datagrid1");
                grid.load({ datajson: json });
            }
        }

        function onSelectGoods(e) {
            var grid2 = mini.get("datagrid2");
            var grid1 = mini.get("datagrid1");
            var rCnt = grid2.getData().length;
            if (rCnt > 0) {
                var rec = grid2.getData();
            }
            else {
                var rec = grid1.getSelecteds();
            }
            if (rec) {
                CloseWindow(rec);
            }
        }

        function adds() {
            var items = grid1.getSelecteds();
            grid1.removeRows(items);
            grid2.addRows(items);
        }
        function addAll() {
            var items = grid1.getData();
            grid1.removeRows(items);
            grid2.addRows(items);
        }
        function removes() {
            var items = grid2.getSelecteds();
            grid2.removeRows(items);
            grid1.addRows(items);
        }
        function removeAll() {
            mini.confirm("确定要全部取消?", "提示", function (action) {
                if (action == "ok") {
                    var items = grid2.getData();
                    grid2.removeRows(items);
                    grid1.addRows(items);
                }
            });
        }
        function selectRow(obj) {
            $("#FMainPic").attr('src', obj.record.FPic);
            $("#FCode").html(obj.record.FCode);
            $("#FSpec").html(obj.record.FSpec);
            $("#FUnit").html(obj.record.FUnitName);
            $("#FConvert").html(obj.record.FConvert);
            $("#FRmoPrice").html(obj.record.FPrice.toFixed(2));
            $("#FNumber").html(obj.record.FNumber);
            $("#FName").html(obj.record.FName);
            $("#FStockQty").html(obj.record.FStockQty.toFixed(2));
        }
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;

            var s = '<a class="New_Button" href="javascript:addRow(\'' + uid + '\')">选择</a>';
            return s;
        }
        function addRow(row_uid) {
            var items = grid1.getRowByUID(row_uid);
            if (items.FRequireStop != 1) {
                grid1.removeRow(items);
                grid2.addRow(items);
            }
        }
        function DrawCell(e) {
            if (e.columnIndex == 2) {
                var PicUrl = e.row.FPic;
                if (PicUrl == '')
                    PicUrl = '/content/images/PImage.jpg';
                e.cellHtml = '<img src="' + PicUrl + '" width="50px" height="40px" />';
            }
        }


    </script>

</form>